<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('服务订单列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input id="orderState" name="orderState" value="0" type="hidden">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label style="width: 100px">下单人电话：</label>
                                <input type="text" name="orderUserPhone"/>
                            </li>
                            <li>
                                <label>地址：</label>
                                <input type="text" name="userAddress"/>
                            </li>
                            <li>
                                <label>联系人：</label>
                                <input type="text" name="userName"/>
                            </li>
                            <li>
                                <label>联系电话：</label>
                                <input type="text" name="userPhone"/>
                            </li>
                            <li>
                                <label>用户类型：</label>
                                <select name="userType" th:with="type=${@dict.getType('user_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li class="select-time">
                                <label style="width: 120px;">订单创建时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginCreateTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endCreateTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="col-sm-12 select-table table-bordered">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('zsyh:serviceOrder:edit')}]];
        var removeFlag = [[${@permission.hasPermi('zsyh:serviceOrder:remove')}]];
        var orderStateDatas = [[${@dict.getType('order_state')}]];
        var userTypeDatas = [[${@dict.getType('user_type')}]];
        var isPriorityDatas = [[${@dict.getType('sys_yes_no')}]];
        var prefix = ctx + "zsyh/serviceOrder";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "服务订单",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                columns: [{
                    field : 'Number',
                    title : '序号',
                    align: 'center',
                    width: 20,
                    formatter : function(value, row, index) {
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                        return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                    }
                },
                {
                    field: 'id',
                    title: '订单编号',
                    align: 'center',
                },
                {
                    field: 'orderUserPhone',
                    align: 'center',
                    title: '下单人联系方式'
                },
                    {
                        field: 'userName',
                        align: 'center',
                        title: '订单联系人'
                    },
                    {
                        field: 'userPhone',
                        align: 'center',
                        title: '订单联系电话'
                    },
                {
                    field: 'userAddress',
                    align: 'center',
                    title: '详细地址'
                },
                {
                    field: 'serviceName',
                    align: 'center',
                    title: '故障类型'
                },
               /* {
                    field: 'faultComment',
                    align: 'center',
                    title: '故障说明'
                },*/
                {
                    field: 'orderState',
                    align: 'center',
                    title: '预约单状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(orderStateDatas, value);
                    }
                },
                /*{
                    field: 'userType',
                    align: 'center',
                    title: '用户类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(userTypeDatas, value);
                    }
                },*/
                /*{
                    field: 'orderNumber',
                    align: 'center',
                    title: '维修数量'
                },*/
                {
                    field: 'cancelRemark',
                    align: 'center',
                    title: '取消订单备注'
                },
                {
                    field: 'orderFixdraw',
                    align: 'center',
                    title: '固定抽成的费用'
                },
                    {
                        field: 'createTime',
                        align: 'center',
                        title: '下单时间'
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="viewDetail(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看详情</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="viewImage(\'' + row.id + '\')"><i class="fa fa-search"></i>查看图片</a> ');
                        if(row.orderState == "0"){
                            actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="cancelOrder(\'' + row.id + '\')"><i class="fa fa-edit"></i>取消订单</a> ');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function viewImage(id) {
            var url = prefix + "/viewImage/"+id;
            layer.open({
                type: 2,
                area: [$(window).width()/1.5 + 'px', ($(window).height() - 50) + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "查看图片",
                content: url,
                btnClose: 1,
                // 弹层外区域关闭
                shadeClose: true,
                yes: function(index, layero) {
                    debugger;
                    var iframeWin = layero.find('iframe')[0];
                    /*var imageUrl = layero.find('iframe')[0].contentWindow.$("#imageUrl").val();*/
                    iframeWin.contentWindow.submitHandler(index, layero);
                },
                cancel: function(index) {
                    return true;
                }
            });
        }

        function cancelOrder(id) {
            var url = prefix + '/cancelOrder/'+id;
            layer.open({
                type: 2,
                area: [$(window).width()/2 + 'px', '350px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "取消订单",
                content: url,
                closeBtn: 1,
                /*btn: ['通过', '驳回'],*/
                // 弹层外区域关闭
                shadeClose: true,
                yes: function(index, layero) {
                    debugger;
                    var iframeWin = layero.find('iframe')[0];
                },
                cancel: function(index) {
                    return true;
                }
            });
        }

        function viewDetail(id) {
            var url = prefix + "/edit/"+id;
            layer.open({
                type: 2,
                area: ['1200px', ($(window).height()-50) + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "查看详情",
                content:  url,
                closeBtn: 1,
                // 弹层外区域关闭
                shadeClose: true,
                end: function(){
                    //location.reload();
                },
                cancel: function(index) {
                    //location.reload();
                }
            });
        }

    </script>
</body>
</html>